package com.hualan.sfzy.service.psyc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.PsycTestOption;
import com.hualan.sfzy.mapper.psyc.PsycTestOptionMapper;
import com.hualan.sfzy.service.psyc.PsycTestOptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PsycTestOptionServiceImpl implements PsycTestOptionService {
    @Override
    public int deleteBatchByTestTitleId(Integer titleId) {
        return topicChooseMapper.deleteBatchByTestTitleId(titleId);
    }

    @Autowired
    private PsycTestOptionMapper topicChooseMapper;
    @Override
    public int add(PsycTestOption entity) {
        return topicChooseMapper.insert(entity);
    }

    @Override
    public int edit(PsycTestOption entity) {
        return topicChooseMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return topicChooseMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return topicChooseMapper.deleteBatch(ids);
    }

    @Override
    public List<PsycTestOption> find() {
        return topicChooseMapper.select(null);
    }
    @Override
    public List<PsycTestOption> findParams(PsycTestOption  entity) {
        return topicChooseMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, PsycTestOption entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<PsycTestOption> list=topicChooseMapper.select(entity);
        PageInfo pageInfo=new PageInfo<>(list);
        Map<String,Object> map=new HashMap<>();
        // map存储当前页数据、总页数、总记录数
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }

    @Override
    public PsycTestOption findById(Integer id) {
        return topicChooseMapper.selectById(id);
    }
    /**
     * 批量插入选项
     * @param topicChooses 选项列表
     * @return 插入成功的数量
     */
    @Override
    public int insertBatch(List<PsycTestOption> topicChooses) {
        return topicChooseMapper.insertBatch(topicChooses);
    }
}
